package 
{
	import datas.Guard;
	import datas.MessageSWF;
	import datas.Monster;
	import datas.Way;
	import datas.datasInterior.MessSWF;
	
	import events.LoadedSWF;
	import events.SWFComplete;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import model.HitTestMonster;
	
	import view.Details;
	import view.FPS;
	import view.MonsterPeo;

	[SWF(width="780",height="480",backgroundColor=0x212121, frameRate="30")]
	public class KingDomRush extends Sprite
	{
		//加载的动态数据信息
		//private var monster:Monster = Monster.getInstance("one");
		//所有的固定数据信息
		private var guard:Guard = Guard.getInstance();
		
		
		//所有的素材(临时使用，交给类库书写者)
		private var details:Details = new Details();
		
		private var index:uint = 0;
		private var value:Boolean = true;
		
		private var die:Boolean = true;

		private var hit:HitTestMonster;
		public function KingDomRush()
		{
			if(!stage)this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
			else onAddedToStage(null);
			
			
		}
		//(临时使用，交给类库书写者)
		protected function onSWFComplete(event:Event):void
		{
			//(临时使用，交给类库书写者)
			addChild(details.bg);
			var most2:MovieClip = details.monster2;
			addChild(most2);
			most2.scaleX = most2.scaleY = 1.5; 
			
			hit = new HitTestMonster(most2 as MovieClip);
			addChild(hit);
			//内存检测
			addChildFPS();
			
			this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}		
		//(临时使用，交给类库书写者)
		protected function onEnterFrame(event:Event):void
		{
			//trace(details.monster2.blood);
			if(details.monster2.x < 800 && details.monster2.blood >=0){
			
				if(index < Way.arr.length-2){
					if(details.monster2.currentFrameLabel == "up")details.monster2.gotoAndPlay("right");
					if(Way.arr[index + 1].x - Way.arr[index].x >= 0){
						if(value != true){
							value = true;
							details.monster2.scaleX *= -1;
							//trace(Way.arr[index + 1].x - Way.arr[index].x);
						}
					}
					else if(Way.arr[index + 1].x - Way.arr[index].x < 0){
						if(value != false){
							value = false;
							details.monster2.scaleX *= -1;
							//trace(Way.arr[index + 1].x - Way.arr[index].x);
						}
					}
				}
				
				details.monster2.x = Way.arr[index].x;
				details.monster2.y = Way.arr[index].y;
				if(index <= Way.arr.length-1)index++;
			}
			else if(die == true){
				die = false;
				details.monster2.gotoAndPlay("die");
				
				//removeChild(details.monster2);
			}
		}		
		
		private function addChildFPS():void
		{
			var fps:FPS = new FPS();
			
			addChild(fps);
			fps.filters = new Array();
		}
		
		protected function onAddedToStage(event:Event):void
		{
			//素材加载完成后(临时使用，交给类库书写者)
			details.addEventListener(SWFComplete.SWFCOMP,onSWFComplete);
		}
	}
}